Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CKKSVector Polynomial Evaluation #99

Merged
merged 25 commits into from
Jul 13, 2020
Merged

CKKSVector Polynomial Evaluation #99

merged 25 commits into from
Jul 13, 2020

Conversation

youben11
Copy link
Member

@youben11 youben11 commented Jul 13, 2020

Description

This PR introduce a new method for CKKSVector to be able to evaluate a polynomial over all the vector values (encrypted_vector.polyval(list_of_polynomial_coefficients))

Fixes #95

How has this been tested?

  • Added tests

Checklist

@youben11 youben11 added the Type: New Feature ➕ Introduction of a completely new addition to the codebase label Jul 13, 2020
@youben11 youben11 requested review from bcebere and philomath213 July 13, 2020 10:52
"the coefficients vector need to have at least one element");
}

int degree = coefficients.size() - 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this generating a warning? I think it should be

static_cast<int>(coefficients.size())

just to keep it a signed integer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should we do that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My confusion here is that coefficients.size() returns size_t, which is an unsigned int64.

Assigning to int should raise some warnings from any compiler, I think.

And you can use

int degree = static_cast<int>(coefficients.size()) - 1;

to prevent the warnings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah of course, didn't saw that I didn't cast, thank you!

// pre-compute squares of x
CKKSVector x = *this;
int max_square = static_cast<int>(floor(log2(degree)));
cout << "max square " << max_square << endl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need stdout logging here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftovers...

int max_square = static_cast<int>(floor(log2(degree)));
cout << "max square " << max_square << endl;
vector<CKKSVector> x_squares;
x_squares.reserve(max_square + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not directly resize? and access the vector directly using [] instead of push_back operations

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: So it's a little complicated for this, reserve is more convenient for our usage, as resize need to init the objects in the vector, and we doesn't want this, however, reserve will only allocate the necessary memory and push_back won't have to allocate memory dynamically.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my observation made more sense with vector of pointers.
Sorry about that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

}

// set result accumulator to the constant coefficient
vector<double> cst_coeff(this->size(), coefficients[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this creates a vector of size this->size() with all the values set to coefficients[0]. is that the expected behavior?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, to encrypt it later and have operations done element-wise

// pre-compute squares of x
CKKSVector x = *this;
int max_square = static_cast<int>(floor(log2(degree)));
vector<CKKSVector> x_squares(max_square + 1);
Copy link
Member

@bcebere bcebere Jul 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the build fails here now, because it tries to call CKKSVector with the default constructor.
If

 vector<CKKSVector> x_squares;
x_squares.resize(max_square + 1);

doesn't work, ignore this, my bad.

Copy link
Member

@bcebere bcebere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@philomath213 philomath213 merged commit 4b0e3f2 into master Jul 13, 2020
@delete-merged-branch delete-merged-branch bot deleted the ckks-polyval branch July 13, 2020 15:47
pierreeliseeflory pushed a commit to pierreeliseeflory/TenSEAL that referenced this pull request Apr 27, 2022
* make it work with tests

* log(n) mul depth for polynomial of degree n

* fix some tests

* rename tests

* some fixes and new tests

* case where poly is of degree < 2

* more tests

* rescale the encrypt_zero ciphertext

* null polynomial tests

* remove debug

* fix _mul_plain_inplace, add some tests

* optimize circuit considering coeffecient

* balancing multiplication circuit

* more tests, docs and TODO

* more tests

* fix bugs, refactor and simplify algorithm

* simplify accumulator creation

* move compute_polynomial_term to utils

* remove inclue <map>

* lint

* requested changes

* cast

* fall back to reserve

Co-authored-by: philomath213 <bilalphilomath@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: New Feature ➕ Introduction of a completely new addition to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Polynomial evaluation for CKKSVector
3 participants